home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- # prm - package remove script
- # copyright (c) 2000, joseph cheek, joseph@redmondlinux.org
- # released under gpl.
- #
- # $1: package to remove. can be full pathname, relative to build root,
- # relative to current dir, relative to col/install/RPMS,
- # relative to col/install/SRPMS, or just rpm package name
- # ex: prm /opt/redmondLinux/builds/21/col/install/SRPMS/mypackage-1.1-1.src.rpm
- # ex: prm col/install/SRPMS/mypackage-1.1-1.src.rpm
- # ex: prm mypackage-1.1-1.src.rpm
- # ex: prm mypackage
- #
- # opts: -q: quiet [don't print status messages]
- # -d: dry run [don't actually perform remove]
- # -v: verbose
- # -l: language to remove from [default: all languages]
-
- # BUG: use getopts instead
- LANG=
- ERROR=0
-
- if [ "n$1" = "n-q" ]; then # -q
- QUIET="-q"
- shift
- fi
-
- if [ "n$1" = "n-d" ]; then # -d
- DRY_RUN="-d"
- shift
- fi
-
- if [ "n$1" = "n-v" ]; then # -v
- VERBOSE="-v"
- shift
- fi
-
- if [ "n$1" = "n-l" ]; then # -l
- LANG="$2"
- shift
- shift
- fi
-
- if [ "$#" -lt 1 ]; then # no args
- ( echo `basename $0`: no arguments given
- echo
- echo usage: `basename $0` \[-q\] \[-d\] \[-v\] \[-l lang\] package.rpm
- echo removes package in redmond linux build system
- echo -q is quiet, ie don\'t print status messages
- echo -d is dry run, ie don\'t perform the rm
- echo -v is verbose
- echo -l is language or all if not present ) >&2
- exit 1
- fi
-
-
- # constants and vars
-
- RL_ROOT=/opt/redmondlinux
- BUILD_NUM_FILE=$RL_ROOT/builds/CURRENT_BUILD
- BUILD_NUM=`cat $BUILD_NUM_FILE`
-
- BUILD_ROOT=$RL_ROOT/builds/$BUILD_NUM
-
- cd $BUILD_ROOT
- LANG_TO_PROCESS=`echo ${LANG}*`
- cd -
- [ $VERBOSE ] && echo Languages to process: $LANG_TO_PROCESS
-
- while [ 1 ]; do # poor substitute for a do..until loop
-
- #
- #
- # check for the file
-
- unset PATH_NAME UPDATED_FILE
- MATCH_FOUND=0
-
- for lang in $LANG_TO_PROCESS; do # check for each language
- [ $VERBOSE ] && echo checking $lang
-
-
- if [ -r "$1" ]; then
- # file found full pathname and relative to current dir cases
- # get fully qualified file name
- pushd `dirname "$1"` > /dev/null
- PATH_NAME=`pwd`/`basename "$1"`
- popd > /dev/null
- MATCH_FOUND=1
-
- elif [ -r "$BUILD_ROOT/$lang/$1" ]; then
- # file found relative to build root
- # get fully qualified file name
- pushd `dirname "$BUILD_ROOT/$lang/$1"` > /dev/null
- PATH_NAME=`pwd`/`basename "$1"`
- popd > /dev/null
- MATCH_FOUND=1
-
- elif [ -r "$BUILD_ROOT/$lang/rl/install/RPMS/$1" ]; then
- # file found relative to rl/install/RPMS
- # get fully qualified file name
- pushd `dirname "$BUILD_ROOT/$lang/rl/install/RPMS/$1"` > /dev/null
- PATH_NAME=`pwd`/`basename "$1"`
- popd > /dev/null
- MATCH_FOUND=1
-
- elif [ -r "$BUILD_ROOT/$lang/rl/install/SRPMS/$1" ]; then
- # file found relative to rl/install/SRPMS
- # get fully qualified file name
- pushd `dirname "$BUILD_ROOT/$lang/rl/install/SRPMS/$1"` > /dev/null
- PATH_NAME=`pwd`/`basename "$1"`
- popd > /dev/null
- MATCH_FOUND=1
-
- elif { PATH_TEST=`echo $BUILD_ROOT/$lang/rl/install/RPMS/$1-[0-9]*.rpm`;
- [ "n$PATH_TEST" != "n" -a -r "$PATH_TEST" ]; }; then
- # file found rpm package name in rl/install/RPMS
-
- # BUG: assumes no numbers start sections of package name
- # [myfile-1st-demo-1.2-21rl.rpm would erroneously match "myfile"]
- # BUG: assumes no letters start versions of package
- # [myfile-a123-21rl.rpm would erroneously not match "myfile"]
-
- # these bugs are trivial IMHO because they can be matched precisely by
- # other methods, above
-
- # get fully qualified file name
- pushd `dirname "$PATH_TEST"` > /dev/null
- PATH_NAME=`pwd`/`basename "$PATH_TEST"`
- popd > /dev/null
- MATCH_FOUND=1
-
- elif { PATH_TEST=`echo $BUILD_ROOT/$lang/rl/install/SRPMS/$1-[0-9]*.rpm`;
- [ "n$PATH_TEST" != "n" -a -r "$PATH_TEST" ]; }; then
- # file found rpm package name in rl/install/SRPMS
-
- # same bugs as above for rl/install/RPMS
-
- # get fully qualified file name
- pushd `dirname "$PATH_TEST"` > /dev/null
- PATH_NAME=`pwd`/`basename "$PATH_TEST"`
- popd > /dev/null
- MATCH_FOUND=1
- fi # big if/elif find file tree
-
- if [ "n$PATH_NAME" = "n" ]; then # file doesn't exist
- echo $1 not found in \[$lang\]
- else # if file exists
- [ $VERBOSE ] && echo file found\! $PATH_NAME
-
- # binary rpm? if so we need to update pkgs.db
-
- if [ `basename "$PATH_NAME" .i386.rpm`.i386.rpm = `basename "$PATH_NAME"` -o \
- `basename "$PATH_NAME" .i486.rpm`.i486.rpm = `basename "$PATH_NAME"` -o \
- `basename "$PATH_NAME" .i586.rpm`.i586.rpm = `basename "$PATH_NAME"` -o \
- `basename "$PATH_NAME" .noarch.rpm`.noarch.rpm = `basename "$PATH_NAME"` ]; then
- # yes, binary rpm
-
-
- #
- #
- # update pkgs.db
-
- # constants and vars
-
- UPDATED_FILE="$PATH_NAME"
-
- # get needed info
-
- eval `rpmextr --shell $UPDATED_FILE` # package name
- PKGS_DB=$BUILD_ROOT/$lang/rl/data/pkgs.db
- DB_LINE=`grep \[A-Z\]*:$PKG_NAME:.* < $PKGS_DB` # line from DB
-
- else # not a binary rpm
- [ $VERBOSE ] && echo not a binary rpm
- fi # binary rpm
-
-
- #
- #
- # perform rm
-
- [ $VERBOSE ] && echo frm $QUIET $VERBOSE -l $lang "$PATH_NAME"
- [ $DRY_RUN ] || frm $QUIET $VERBOSE -l $lang "$PATH_NAME"
- RETURN=$?
- [ $VERBOSE ] && echo frm returned $RETURN
- [ $RETURN -gt 0 ] && exit $RETURN # assumes frm will print error msg
-
- if [ "n$UPDATED_FILE" != "n" ]; then # update pkgs.db
- [ $VERBOSE ] && echo -n binary rpm,\
- echo current line \[$lang\]: $DB_LINE
- echo it will need removing
- fi
-
- fi # file doesn't exist
-
- done # for each language
-
- if [ $MATCH_FOUND = 0 ]; then
- [ $VERBOSE ] && echo no match found\! time to leave...
- break
- fi
-
- done # poor substitute for a do..until loop
-